<?
$apache2_siteconf = "/etc/apache2/sites-available/default";
$shareDir = "/var/shares/";

function showbase() {
	global $apache2_siteconf;
	global $shareDir;

	$str_conf = file_get_contents($apache2_siteconf);

	/* servernamn och admin, används ej */
	//preg_match('/\s*serveradmin\s*([^\s]*)\s*/i', $str_conf , $match);
	//$serveradm = $match[1];
	//preg_match('/\s*servername\s*([^\s]*)\s*/i', $str_conf , $match);
	//$servername = $match[1];

	preg_match('/\s*documentroot\s*([^\s]*)\s*/i', $str_conf , $match);
	$directory = $match[1];

	preg_match('/\s*<Directory '.str_replace('/', '\/', $directory).'[\/ ]?>(.*?)<\/Directory>/smi', $str_conf , $match);
	preg_match('/allow from ([^\s]*)/i', $match[1] , $match);
	if( $match[1] == 'all' )
		$active = true;
	else
		$active = false;


	echo '<div '.help('site_activate').'>';
	if( $active )
		echo '<input name="server_active" type="checkbox" onClick="javascript:change_select()" checked>';
	else
		echo '<input name="server_active" type="checkbox" onClick="javascript:change_select()">';
	echo ' Hemsida aktiv</div>';

	echo '<table>';
	echo '<tr '.help('directory').'>';
	echo '<td>Katalog med hemsideinnehåll </td>';
	echo '<td><select name="directory">';
	
	if( $directory != "" ) {
		preg_match('@'.$shareDir.'(.*)@', $directory , $match);
		echo '<option value="'.$directory.'" selected>'.$match[1];
	}

	$dh  = opendir($shareDir);
	while (false !== ($thing = readdir($dh))) {
		if (is_dir("$shareDir$thing") && $thing != "." && $thing != "..") {
			if( $directory != $shareDir.$thing )
				echo '<option value="'.$shareDir.$thing.'">'.$thing;
		}
	}
	closedir($dh);
	
	echo '</select></td></tr>';
	echo '</table><br>';

	/*
	echo '<table>';
	echo '<tr><td>Servernamn </td><td><input name="servername" value="'.$servername.'" type="text"></td></tr>';
	echo '<tr><td>Administratörsmail </td><td><input name="serveradm" value="'.$serveradm.'" type="text"></td></tr>';
	echo '</table><br>';
	*/

	echo '
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function change_select()
{
	if( document.pageform.server_active.checked == true ) {
		document.pageform.directory.disabled=false;
	}
	else {
		document.pageform.directory.disabled=true;
	}
}
change_select();
-->
</SCRIPT>
	';
}

////////////////////////////
////////////////////////////


$tabsmain = array( 
	array('web','Webserver'), 
	);

switch( $_GET['t'] ) {
default:
case 'web':
	html_start( $tabsmain );
	showbase();
	html_end(true, true, true);
	break;
}


?>
